home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / LWP / Protocol / data.pm next >
Encoding:
Perl POD Document  |  1999-12-28  |  1.1 KB  |  47 lines

  1.  
  2. package LWP::Protocol::data;
  3.  
  4. require HTTP::Response;
  5. require HTTP::Status;
  6.  
  7. require LWP::Protocol;
  8. @ISA = qw(LWP::Protocol);
  9.  
  10. use HTTP::Date qw(time2str);
  11. require LWP;  # needs version number
  12.  
  13. sub request
  14. {
  15.     my($self, $request, $proxy, $arg, $size) = @_;
  16.  
  17.     if (defined $proxy)
  18.     {
  19.     return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
  20.                   'You can not proxy with data';
  21.     }
  22.  
  23.     if ($request->method ne 'GET') {
  24.     return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
  25.                   'Library does not allow method ' .
  26.                   "$method for 'data:' URLs";
  27.     }
  28.  
  29.     my $url = $request->url;
  30.     my $response = new HTTP::Response &HTTP::Status::RC_OK, "Document follows";
  31.  
  32.     my($media_type, $params) = $url->media_type;
  33.     $media_type .= ";$params" if $params;
  34.  
  35.     my $data = $url->data;
  36.     $response->header('Content-Type'   => $media_type,
  37.               'Content-Length' => length($data),
  38.               'Date'           => time2str(time),
  39.               'Server'         => "libwww-perl-internal/$LWP::VERSION"
  40.              );
  41.     $response->content($data);
  42.  
  43.     return $response;
  44. }
  45.  
  46. 1;
  47.